<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>版本更新</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link href="https://gitee.com/hubert47/update_version/raw/main/base/amazeui.css" rel="stylesheet">
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://gitee.com/hubert47/update_version/raw/main/base/amazeui.js"></script>
    <script src="https://gitee.com/hubert47/update_version/raw/main/base/amazeui.ie8polyfill.js"></script>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
            border: 0;
        }

        html {
            font-size: 62.5%;
        }

        body {
            font-size: 1.6rem;
            /* =16px */
        }


    </style>

</head>

<body>

<header data-am-widget="header" class="am-header am-header-default">


    <h1 class="am-header-title">
        <a href="#title-link" class="">
            联众金融
        </a>
    </h1>

</header>
<form class="am-form" id="Form" method="post" onsubmit="return false;">
    <fieldset>

        <div class="am-form-group">
            <label for="doc-select-1">os</label>
            <select id="doc-select-1" name="os" value="" onchange="initApkUrl()">
                <option value="androidSales">联众金融+android-生产</option>
                <option value="androidPre">联众金融+android-预发布</option>
                <option value="androidKKC">联众快开车android</option>
                <option value="androidYM">誉米标服</option>
            </select>
            <span class="am-form-caret"></span>
        </div>

        <div class="am-form-group">
            <label for="doc-ipt-email-1">versionCode</label>
            <input type="number" id="doc-ipt-email-1" name="version" value="" placeholder="输入版本号">
        </div>

        <div class="am-form-group">
            <label for="doc-ipt-pwd-1">url</label>
            <input class="apkUrl" type="url" name="url" id="doc-ipt-pwd-1" value="https://app.lianzhongjr.com/apk-finance-plus/apk-finance-plus.apk" placeholder="新版本地址">
        </div>


        <div class="am-form-group">
            <label for="doc-ta-1">更新内容</label>
            <textarea class="" rows="5" name="content" id="doc-ta-1" value=""></textarea>
        </div>

        <p>
            <button type="button" onclick="submitForm();" class="am-btn am-btn-default">更新</button>
        </p>
        <p>
            <button type="button" onclick="checkVersion();" class="am-btn am-btn-default">查看当前版本
            </button>
        </p>
    </fieldset>
</form>

<script>
        function initApkUrl() {
             var os = $("select[name='os']").val();
             if (os =='androidSales'){
                $('.apkUrl').val('https://app.lianzhongjr.com/apk-finance-plus/apk-finance-plus.apk')
             } else if (os == 'androidKKC'){
                $('.apkUrl').val('http://apps-dl.lianzhongjr.com/apk-kuaikaiche/apk-kuaikaiche.apk')
             } else if (os == 'androidYM'){
                $('.apkUrl').val('http://app.lianzhongjr.com/yumi-apk/yumi.apk')
             } else {
                $('.apkUrl').val('')
             }
        }
        /*这里是提交表单前的非空校验*/
        function submitForm() {
            var os = $("select[name='os']").val();
            var version = $("input[name='version']").val();
            var url = $.trim($("input[name='url']").val());
            var content = $("textarea[name='content']").val();

            if (os == '' || version =='' ||url==''||content=='') {
                alert("请输入完整更新信息");
                return false;
            }

            if (!confirm("确定要更新吗？" + "\nos->" + os +
                "\nversion->" + version +
                "\ncontent->" + content +
                "\nurl->" + url)) {
                return false;
            }

            $.ajax({
                type: "POST",
                url: "http://ufapi.lianzhongjr.com/lzjrapi/loanapply/version/add",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify({
                    "os": os,
                    "version": version,
                    "content": content,
                    "url": url
                }),
                dataType: "json",
                async: false,
                success: function (res) {
                    if (res.code == "00") {
                        alert("更新成功");
                    } else {
                        alert(res.message);
                    }

                },
                error: function (message) {
                    alert("更新失败" + JSON.stringify(message));
                }
            });
        }

        function checkVersion() {
            var os = $("select[name='os']").val();
            if (os == '') {
                alert("请选择系统");
                return false;
            }
            $.ajax({
                type: "GET",
                url: "http://ufapi.lianzhongjr.com/lzjrapi/loanapply/version/getVersion?os=" + os,
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                async: false,
                success: function (res) {
                    if (res.code == "00" && res.data != null) {
                        alert("当前版本" + "\nos->" + res.data.os +
                            "\nversion->" + res.data.version +
                            "\ncontent->" + res.data.content +
                            "\nurl->" + res.data.url +
                            "\ncreateTime->" + res.data.createTime)
                    } else {
                        alert(res.message)
                    }

                },
                error: function (res) {
                    alert("查看失败->" + res);
                }
            });
        }


</script>

</body>

</html>